﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Collections;
using cn.Util;

namespace yq.ControllerBase
{
    /// <summary>
    /// 当前用户
    /// </summary>
    [Serializable]
    public class CurrentUser
    {
        private const string Key = "CurrentUser";

        /// <summary>
        /// 是否在线
        /// </summary>
        public bool IsLogin
        {
            get
            {
                return GetUser<object>() != null;
            }
        }

        /// <summary>
        /// 获取当前用户信息
        /// </summary>
        /// <returns></returns>
        public virtual T GetUser<T>() where T : class,new()
        {
            return HttpContext.Current.Session==null? new T():  HttpContext.Current.Session[Key] as T;
        }

       
        /// <summary>
        /// 写入用户
        /// </summary>
        /// <param name="user"></param>
        public virtual void SetUser<T>(T user)
        {
            HttpContext.Current.Session[Key] = user;
        }
    }
}
